import UIManager from "../UIManager";
import Util from "../utils/Util";
import UIBase from "./UIBase";

const { ccclass, property } = cc._decorator;

@ccclass
export default class LosePanel extends UIBase {

    @property(cc.Node)
    playAgainButton: cc.Node = null
    @property(cc.Node)
    backToMenuButton: cc.Node = null

    private _uiManager: UIManager = null

    onLoad() {
        super.onLoad()
    }

    public init(uiManager: UIManager) {
        this._uiManager = uiManager

        // 事件监听
        const { TOUCH_START, TOUCH_END, TOUCH_CANCEL } = cc.Node.EventType

        // 返回首页按钮
        this.backToMenuButton.on(TOUCH_START, () => { Util.clickDownTween(this.backToMenuButton) })
        this.backToMenuButton.on(TOUCH_END, () => {
            Util.clickUpTween(this.backToMenuButton, () => {
                this._uiManager.onClickToStartMenu()
            })
        })
        this.backToMenuButton.on(TOUCH_CANCEL, () => { Util.clickUpTween(this.backToMenuButton) })

        // 下一关按钮
        this.playAgainButton.on(TOUCH_START, () => { Util.clickDownTween(this.playAgainButton) })
        this.playAgainButton.on(TOUCH_END, () => {
            Util.clickUpTween(this.playAgainButton, () => {
                this._uiManager.onClickPlayAgain()
            })
        })
        this.playAgainButton.on(TOUCH_CANCEL, () => { Util.clickUpTween(this.playAgainButton) })
    }

}
